<?php
/**
 * Utility functions
 *
 * @author      Hyper <hyper@flashbay.com>
 * @copyright   Copyright (c) 2011 (http://www.saleshero.com)
 */
class SalesHero_Util
{

    /**
     * Highlight keyword of
     *
     * @param string    $string
     * @param mix       $keyword
     * @return string
     */
    public static function highlight($string, $keyword)
    {
        if ($string && $keyword) {
            if (!is_array($keyword)) {
                $keyword = array($keyword);
            }
            $pattern = array();
            foreach ($keyword as $word) {
                $pattern[] = '(' . preg_quote($word) . ')';
            }
            $string = preg_replace(
                '/(' . implode('|', $pattern) . ')/is',
                '<span class="highlight">\\1</span>',
                $string
            );
        }
        return $string;
    }

}